﻿@model PagedList.IPagedList<KhatVongViet.Models.Article>
@using PagedList.Mvc;
@{
    ViewBag.Title = "Khát Vọng Việt - Quản Lý Confession";
    Layout = "~/Views/Administrator/Layout.cshtml";
}
<script type="text/javascript">
    $(function () {

    });
    function cbChanged(checkboxElem) {
        var value = checkboxElem.checked ? true : false;
        var id = checkboxElem.id;

        if (checkboxElem.checked) {
            $.ajax({
                url: '/Administrator/UpdatePinArticle',
                type: 'POST',
                data: {
                    pinId: id,
                    valuePublish: value
                },
                success: function (data) {
                    location.reload(true);
                },
                error: function () {
                    alert("error");
                }
            });
        }
        else 
        {
            $.ajax({
                url: '/Administrator/UpdatePinArticle',
                type: 'POST',
                data: {
                    pinId: id,
                    valuePublish: value
                },
                success: function (data) {
                    location.reload(true);
                },
                error: function () {
                    alert("error");
                }
            });
        }
    }
</script>

@using (Html.BeginForm("ManageConfession", "Administrator", FormMethod.Get, new { id = "manage-confession" }))
{
    <p>
        Tìm theo tựa bài: @Html.TextBox("SearchString", ViewBag.CurrentFilter as string)
        <input type="submit" value="Search" />
    </p>
}
<table>
    <tr>
        <th>
            @Html.ActionLink("Tên Confession", "ManageConfession", new { sortOrder = ViewBag.NameSortParm, currentFilter = ViewBag.CurrentFilter })
        </th>
        <th>
            @Html.ActionLink("Ngày tạo", "ManageConfession", new { sortOrder = ViewBag.DateSortParm, currentFilter = ViewBag.CurrentFilter })
        </th>
        <th>
            Hiển thị
        </th>
        <th>
            Email
        </th>
        <th>
            Tùy chọn
        </th>
    </tr>
    @{
        foreach (var item in Model)
        {
        <tr>
            <td>
                @if (!item.Title.IsEmpty())
                {
                    @Html.ActionLink(item.Title, "Detail", "Confession", new { idConfession = item.ID }, null)
                }
                else
                {
                    @Html.ActionLink("No title", "Detail", "Confession", new { idConfession = item.ID }, null)   
                }
            </td>
            <td>
                @item.DateCreate
            </td>
            <td>
                @Html.CheckBox("pin" + @item.ID, item.Publish != false ? true : false, new { id = @item.ID, onClick = "cbChanged(this)" })
            </td>
            <td>
                @item.Email
            </td>
            <td>
                @Html.ActionLink("Edit", "EditConfession", new { id = item.ID }, null) |
                @Html.ActionLink("Delete", "DeleteCofession", new { id = item.ID }, new { onclick = "return confirm('Bạn thực sự muốn xóa confession này không?');" })
            </td>
        </tr>
        }
    }
</table>
<br />
Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber)
of @Model.PageCount
@Html.PagedListPager(Model, page => Url.Action("ManageConfession", new { page, sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter }))
